const { createGzip } = require('zlib');
const { pipeline } = require('stream');
const {
    createReadStream,
    createWriteStream
} = require('fs');

const gzip = createGzip();
const source = createReadStream('input1.txt');
const destination = createWriteStream('input1.gz');
//执行压缩
pipeline(source, gzip, destination, (err) => {
    if (err) {
        console.error('发生一个错误:', err);
        process.exitCode = 1;
    }
});